<template>
  <div class="count">
    <h2>Count组件:{{ count }}</h2>
    <p>总价格是:{{ totalPrice }}</p>
    <button @click="increment">累加count</button>
    <button @click="incrementN({ n: 3 })">累加N count</button>
    <button @click="incrementWait">等两秒再累加</button>
    <button @click="incrementNWait({ n: 3 })">等两秒再累加N</button>
  </div>
</template>

<script>
import { mapState, mapGetters, mapMutations, mapActions } from "vuex";
export default {
  name: "Count",
  mounted() {
    /* const result = mapActions(["incrementWait", "incrementNWait"]);
    console.log(result);
    console.log(result.incrementWait.call(this)); */
  },
  computed: {
    ...mapState(["count", "num"]),
    ...mapGetters(["totalPrice"]),
  },
  methods: {
    ...mapMutations(["increment", "incrementN"]),

    /* 
      mapActions辅助函数 方便我们得到一个包含 派发actions函数 组成的对象
      参数两种:数组 对象
    */
    // ...mapActions({incrementWait:"incrementWait",incrementNWait:"incrementNWait"}),
    ...mapActions(["incrementWait", "incrementNWait"]),

    /* incrementWait() {
      // console.log(this);
      this.$store.dispatch("incrementWait");
    },

    incrementNWait(payload) {
      this.$store.dispatch("incrementNWait", payload);
    }, */
  },
};
</script>

<style scoped>
.count {
  background-color: pink;
}
</style>
